{layout name="public/layout" /}
{include file='yxnavbar'}


<style type="text/css">
    .str_center{
        height: 80px;
        line-height: 80px !important;
    }
</style>
<div class="main">
    {include file='../../plugin/beilai/template/web/common_nav'}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="r" value="beilai" />
                <input type="hidden" name="do" value="web" />
                <div class="form-group">
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <a href="{php echo createWebUrlPlugin('beilai.add',array('themeid'=>$themeid));}" class="btn btn-primary">添加课程</a>
                    </div>
                    {if count($shangjia)>0 }
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="shangjiaid">
                            {loop $shangjia $row}
                            <option value="{$row['id']}" {if $shangjiaid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['name'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="shangjiaid" value="{$shangjiaid}" />
                    {/if}
                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键字</label>
                    <div class="col-sm-4 col-xs-4 col-md-4">
                        <input class="form-control" name="name" placeholder="输入课程名称" type="text" value="{$_P['name']}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-body table-responsive">
            <table class="table table-hover">
                <thead class="navbar-inner">
                <tr>
                    <th style="width:50px;">
                    <a href="{php echo createWebUrlPlugin('beilai',array('themeid'=>$themeid,'sort'=>'a.id','key'=>$key));}">
                        序号
                    </a>
                    </th>
                    <th style="width:120px;">课程头图</th>
                    <th style="width:120px;">
                        <a href="{php echo createWebUrlPlugin('beilai',array('themeid'=>$themeid,'sort'=>'name','key'=>$key));}">
                            课程名称
                        </a>
                    </th>
                    <th style="width:120px;"><a href="{php echo createWebUrlPlugin('beilai',array('themeid'=>$themeid,'sort'=>'price','key'=>$key));}">
                        课程市场价
                    </a></th>

                    <th style="width:120px;">所属商家</th>
<!--                    <th style="width:120px;">库存</th>-->
                    <th style="width:120px;">
                        <a href="{php echo createWebUrlPlugin('beilai',array('themeid'=>$themeid,'sort'=>'a.status','key'=>$key));}">
                            状态
                        </a>
                    </th>

                    <th style="width:100px; text-align:right;">操作</th>
                </tr>
                </thead>
                <tbody>
                {loop $list $key $item}
                <tr class="str_center">
                    <td class="str_center">{php echo $key+1;}</td>
                    <td class="str_center"><img src="{php echo tomedia($item['top_img']);}" style="width: 100px;height: 80px;padding: 1px;"></td>
                    <td class="str_center">{$item['name']}</td>
                    <td class="str_center">￥ {$item['price']}</td>
                    <td class="str_center">{$item['shangjia_name']}</td>
<!--                    <td class="str_center">-->
<!--                        <a class="btn btn-warning btn-sm" style="white-space: nowrap;" onclick="editItemQty(this)" data-action="add" data-themeid="{$themeid}" data-id="{$item['id']}" title="添加库存" data-toggle="tooltip" data-placement="top" >-->
<!--                            <i class="fa fa-plus" style="white-space: nowrap;" aria-hidden="true"></i></i>-->
<!--                        </a>-->
<!--                        {$item['qty']}-->
<!--                        {if $item['qty']>0}-->
<!--                        <a class="btn btn-danger btn-sm" style="white-space: nowrap;" onclick="editItemQty(this)" data-action="minus" data-themeid="{$themeid}" data-id="{$item['id']}" title="减少库存" data-toggle="tooltip" data-placement="top" >-->
<!--                            <i class="fa fa-minus" style="white-space: nowrap;" aria-hidden="true"></i></i>-->
<!--                        </a>-->
<!--                        {/if}-->
<!--                    </td>-->
                    <td class="str_center">
                        {if $item['status']==1}
                        <span class="label label-success">活动可选</span>
                        {else}
                        <span class="label label-default">活动不可选</span>
                        {/if}
                    </td>
                    <td class="str_center" style="text-align:right;">
                        {if $key!=0}
                        <a class="btn btn-success btn-sm" onclick="editItemSort(this)" data-action="up" data-sort="{$item['show_sort']}" data-themeid="{$themeid}" data-id="{$item['id']}" title="向上移动" data-toggle="tooltip" data-placement="top" ><i class="fa fa-chevron-up" aria-hidden="true"></i></i></a>
                        {else}
                        {/if}
                        {if ($key+1)!=count($list)}
                        <a class="btn btn-success btn-sm" onclick="editItemSort(this)" data-action="down" data-sort="{$item['show_sort']}" data-themeid="{$themeid}" data-id="{$item['id']}" title="向下移动" data-toggle="tooltip" data-placement="top"><i class="fa fa-chevron-down" aria-hidden="true"></i></a>
                        {else}
                        {/if}
                        <a class="btn btn-warning btn-sm" href="{php echo createWebUrlPlugin('beilai.edit',array('themeid'=>$themeid,'id'=>$item['id']));}"  title="编辑"><i class="icon-edit"></i>编辑</a>
<!--                        <a onclick="changeOrDelItem(this)"-->
<!--                           data-edit-url="{php echo createWebUrlPlugin('beilai.del');}" data-action="del"-->
<!--                           data-id="{$item['id']}" data-themeid="{$themeid}"  title="删除" style="width: 30px" class="btn btn-danger btn-sm"  data-toggle="tooltip" data-placement="top"><i class="fa fa-times"> </i></a>-->
                    </td>
                </tr>
                {/loop}
                </tbody>
            </table>
        </div>
    </div>
</div>
{$pager}
<script type="text/javascript">
    function submitForm(){
        var form = document.getElementById("myform");
        form.submit();
    }
    function editItemSort(e){
        let id = e.getAttribute("data-id");
        let action = e.getAttribute("data-action");
        let themeid = e.getAttribute("data-themeid");
        let sort = e.getAttribute("data-sort");
        var postUrl = "{php echo createWebUrlPlugin('beilai.editSortItem');}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data: {id:id,themeid:themeid,action:action,sort:sort},
            success:function (e) {
                let res = e.result;
                let status = res.status;
                let msg = res.msg;
                if (status!=1){
                    layer.msg(msg);
                }else{
                    layer.msg(msg);
                }
                location.reload();
            },
            fail:function (err) {
                console.log(err)
            }
        });
    }
    //修改奖品库存
    function editItemQty(e){
        let action = e.getAttribute("data-action");
        let id = e.getAttribute("data-id");
        let themeid = e.getAttribute("data-themeid");
        var postUrl = "{php echo createWebUrlPlugin('beilai.editItemQty');}";

        var title_str = '';
        if (action=='add'){
            title_str = '请输入增加库存数';
        }else{
            title_str = '请输入减少库存数';
        }
        layer.prompt({
            formType: 3,
            value: 1,
            title: title_str,
            area: ['300px', '50px'] //自定义文本域宽高
        }, function(value, index, elem){
            layer.close(index);
            $.ajax({
                url:postUrl,
                dataType:'json',
                method:'post',
                data: {id:id,themeid:themeid,action:action,op_num:value},
                success:function (e) {
                    let res = e.result;
                    let status = e.status;
                    if (status!=1){
                        layer.msg(res.message);
                    }else{
                        layer.msg(res.msg);
                    }
                    location.reload();
                },
                fail:function (err) {
                    console.log(err)
                }
            });
        });


    }
    // 修改、删除
    function changeOrDelItem(e) {
        let f_id = e.getAttribute("data-id");
        let action = e.getAttribute("data-action");
        let uid = e.getAttribute("data-uid");
        let themeid = e.getAttribute("data-themeid");
        let postUrl =e.getAttribute("data-edit-url");
        if (action=='del'){
            layer.msg('您确定核销该奖品吗？',{
                btn:['确定','取消'],
                yes:function (index) {
                    $.ajax({
                        url:postUrl,
                        dataType:'json',
                        method:'post',
                        data: {f_id:f_id,themeid:themeid,uid:uid,p_id:p_id},
                        success:function (e) {
                            let res = e.result;
                            let status = res.status;
                            let msg = res.msg;
                            if (status!=1){
                                layer.msg(msg);
                            }else{
                                layer.msg(msg);
                            }
                            window.parent.location.reload();
                        },
                        fail:function (err) {
                            console.log(err)
                        }
                    });

                }
            });
        }else{

        }
    }
</script>
